package com.ptszyxx.popose.module.main.user.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.ysg.base.BaseViewModel;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.BaseResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.http.data.entity.user.UserGiftResult;

import java.util.HashMap;
import java.util.Map;

public class UserDetailMineVM extends BaseViewModel<CommonRepository> {
    public String userId;
    public ObservableField<UserGiftResult> entity = new ObservableField<>();
    public ObservableField<String> sex = new ObservableField<>();

    public UserDetailMineVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onGiftEvent = new SingleLiveEvent<>();
        public SingleLiveEvent onLabelEvent = new SingleLiveEvent<>();
    }

    public void requestUserGift(){
        Map<String, String> map = new HashMap<>();
        map.put("userid", userId);

        HttpUtils.getInstance()
                .data(model.userGift(map), this,
                        new OnSuccessResult<UserGiftResult>() {
                            @Override
                            public void onSuccessResult(BaseResponse<UserGiftResult> response) {
                                UserGiftResult result = response.getData();
                                if (result != null){
                                    entity.set(result);
                                    uc.onGiftEvent.setValue(result.getGiftList());
                                    uc.onLabelEvent.setValue(result.getBiaoqian());
                                }
                            }
                        });
    }

}
